<?php
/**
 * 文章分类模板
 */

use kartik\grid\GridView;
use yii\helpers\Html;
use common\models\DAO\ProductType;

$gridColumns = [
    ['class' => 'kartik\grid\SerialColumn'],
    [
        'attribute' => 'typeName',
        'format' => 'html',
        'value' => function($model){
            if(!$model->parentID){
                $html = $model->typeName . '&nbsp;' . Html::a('[下级分类]', ['type/list', 'id'=>$model->id]);
            }else{
                $html = Html::a($model->typeName, ['product/list', 'id'=>$model->id]);
            }
            return $html;
        }
    ],
    [
        'attribute' => 'parentID',
        'value' => function($model){
            if($model->parentID){
                $parent = ProductType::findOne($model->parentID);
                return $parent->typeName;
            }
            return '';
        }
    ],
    [
        'attribute' => 'adminID',
        'value' => 'admin.realName',
    ],
    
    'createTime:datetime',
    [
        'class' => 'common\widgets\KartikActionColumn',
        'items' => [
            ['修改', 'type/edit', 'btn-primary'],
            ['删除', 'type/del', 'btn-danger'],
        ]
    ]
];

echo GridView::widget([
    'dataProvider' => $dataProvider,
    'toolbar'=> [
        ['content' => Html::a('<i class="glyphicon glyphicon-plus"></i> 添加产品分类', ['type/add'], ['class' => 'btn btn-primary'])],
        '{toggleData}',
    ],
    'showPageSummary' => true,
    'panel' => [
        'type' => GridView::TYPE_DEFAULT,
        'heading' => $this->title,
    ],
    'columns' => $gridColumns,
]);